package com.jprocms.module.cms.dal.mysql.comment;

import com.jpro.framework.common.pojo.PageResult;
import com.jpro.framework.mybatis.core.mapper.BaseMapperX;
import com.jpro.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.jprocms.module.cms.controller.admin.comment.vo.CommentPageReqVO;
import com.jprocms.module.cms.dal.dataobject.comment.CommentDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 内容评论 Mapper
 *
 * @author jprocms
 */
@Mapper
public interface CommentMapper extends BaseMapperX<CommentDO> {

    default PageResult<CommentDO> selectPage(CommentPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<CommentDO>()
                .eqIfPresent(CommentDO::getCreateUserIp, reqVO.getCreateUserIp())
                .eqIfPresent(CommentDO::getContentId, reqVO.getContentId())
                .eqIfPresent(CommentDO::getSiteId, reqVO.getSiteId())
                .eqIfPresent(CommentDO::getStatus, reqVO.getStatus())
                .betweenIfPresent(CommentDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(CommentDO::getId));
    }

    default List<CommentDO> selectList(CommentPageReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<CommentDO>()
                .eqIfPresent(CommentDO::getCreateUserIp, reqVO.getCreateUserIp())
                .eqIfPresent(CommentDO::getContentId, reqVO.getContentId())
                .eqIfPresent(CommentDO::getSiteId, reqVO.getSiteId())
                .eqIfPresent(CommentDO::getStatus, reqVO.getStatus())
                .betweenIfPresent(CommentDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(CommentDO::getId));
    }
}